import time

import allure

from base.base_page import BasePage

from pages import phone_loc, verify1_code_loc, password1_loc, password2_loc, invite_phone_loc, \
    success1_text_loc, error1_text_loc, register_button_loc, agree_loc, reg_alert_btn_loc


# def test_register_assert(data):
#     username = data["phone"]
#     verify_code = data["verify_code"]
#     password1 = data["password1"]
#     password2 = data["password2"]
#     invite=data[""]
#     expected_error = data["expected_error"]


class PageRegister(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.__phone_loc=phone_loc  #用户名
        self.__verify1_code_loc=verify1_code_loc   #验证码
        self.__password1_loc = password1_loc  # 密码
        self.__password2_loc = password2_loc
        self.__invite_loc=invite_phone_loc  #推荐人手机号非必填
        self.__agree_loc=agree_loc #勾选协议
        self.__register_button_loc = register_button_loc  #登录按钮
        self.__success1_text_loc=success1_text_loc#登录成功文本
        self.__error1_text_loc=error1_text_loc#登录失败文本
        self.__reg_alert_btn_loc = reg_alert_btn_loc
    #输入用户名
    @allure.step("1.输入手机号")
    def __input_phone(self,phone):
        # *self.username_loc  解包
        # self.__driver.find_element(*self.__username_loc).send_keys(username)
        self.input_value(self.__phone_loc,phone)

        # 输入验证码
    @allure.step("2.输入验证码")
    def __input_verify1_code(self, verify1_code):
            # self.__driver.find_element(*self.__verify_code_loc).send_keys(verify_code)
        self.input_value(self.__verify1_code_loc, verify1_code)
    #输入密码
    @allure.step("3.输入密码1")
    def __input_password1(self,password1):
        # self.__driver.find_element(*self.__password_loc).send_keys(password)
        self.input_value(self.__password1_loc,password1)

    @allure.step("4.输入密码2")
    def __input_password2(self, password2):
        # self.__driver.find_element(*self.__password_loc).send_keys(password)
        self.input_value(self.__password2_loc, password2)

    #输入推荐人手机号
    @allure.step("5.输入推荐人手机号")
    def __input_invite_phone(self,invite):
        self.input_value(self.__invite_loc,invite)
    #勾选协议
    @allure.step("6.勾选协议")
    def __click_agree(self):
        if self.element_is_selected(self.__agree_loc):
            return
        else:
            self.click_element(self.__agree_loc)
    #点击登录
    @allure.step("7.点击注册")
    def __click_register_button(self):
        # self.__driver.find_element(*self.__login_button_loc).click()
        self.click_element(self.__register_button_loc)
    #获取登录成功的文本信息
    @allure.step("8.获取登录成功的文本信息")
    def get_register_success1_text(self):
        # time.sleep(2)
        # return self.__driver.find_element(*self.__success_text_loc).text
        return self.get_element_text(self.__success1_text_loc)
    #获取登录失败的文本信息
    @allure.step("9.获取登录失败的文本信息")
    def get_register_error1_text(self):
        # time.sleep(2)
        # return self.__driver.find_element(*self.__error_text_loc).text
        return self.get_element_text(self.__error1_text_loc)

    def register(self,phone,verify1_code,password1,password2,invite):
        self.__input_phone(phone)
        self.__input_verify1_code(verify1_code)

        self.__input_password1(password1)
        self.__input_password2(password2)
        self.__input_invite_phone(invite)
        if(len(password1)<6 or len(password1)>16) or (len(password2)<6 or len(password2)>16):
            self.click_element(self.__reg_alert_btn_loc)
        self.__click_agree()
        self.__click_register_button()

